class Solution {
    public int cuttingRope(int n) {
        if (n == 2) {
            return 1;
        }
        if (n == 3) {
            return 2;
        }
        int a = n / 3;
        int b = n % 3;
        if (b == 0) {
            return (int) pow(3, a);
        } else if (b == 1) {
            return (int) (pow(3, a - 1) * 4 % 1000000007);
        } else {
            return (int) (pow(3, a) * 2 % 1000000007);
        }
    }

    private long pow(int m, int n) {
        if (n == 0) {
            return 1;
        }
        long sum = m;
        for (int i = 0; i < n - 1; i++) {
            sum *= m;
            if (sum > 1000000007) {
                sum %= 1000000007;
            }
        }
        return sum;
    }

    public static void main(String[] args) {
        Solution s = new Solution();
        System.out.println(s.pow(3, 4));
        int res = s.cuttingRope(127);
        System.out.println(res);
    }
}